//
//  RoomInfoViewController.m
//  YMRTC
//
//  Created by admin on 2022/4/20.
//

#import "RoomInfoViewController.h"
#import <Masonry/Masonry.h>
#import "GroupNameViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <MJExtension/MJExtension.h>
#import "UIViewController+HUD.h"
#import "GroupCollectionViewCell.h"
#import "ContactViewController.h"
#import <YYKit.h>   // 富文本

@interface RoomInfoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UIImageView *headImageView;
@property (nonatomic,strong)UILabel *nameLable;
@property (nonatomic,strong)UILabel *roomLable;
@property (nonatomic,strong)UIView *headerView;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIView *footerView;
@property (nonatomic,strong)UIButton *deleteButton;
@property (nonatomic,strong)UILabel *nickNameLable;
@property (nonatomic,strong)UILabel *inforLable;
@property (nonatomic,strong)UILabel *numLable;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,assign)NSInteger userType;//0 管理员 1聊天室成员
@property (nonatomic,assign)NSInteger muteType;//0 未禁言 1已禁言
@property (nonatomic, assign) NSInteger isTop;//置顶
@property (nonatomic, assign) NSInteger isDisturb;//免打扰
@property (nonatomic,strong)UISwitch *distubSwithBtn;
@property (nonatomic,strong)UISwitch *skiTopSwithBtn;
@property (nonatomic,strong)NSString *nickName;

@end

@implementation RoomInfoViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = @"聊天室详情";
    self.view.backgroundColor = [UIColor whiteColor];
    self.dataArray = [NSMutableArray array];
    [self initview];
    [self initCollectionView];
    [self loadData];
 
    // Do any additional setup after loading the view.
}
#pragma mark 获取聊天室详情
-(void)loadData{
    
    [[YMIMClient sharedClient].chatManager getConversationWithTargetId:self.roomId completion:^(YMConversation * _Nonnull conversation, YMErrorCode code) {
     
        [self.dataArray removeAllObjects];
        
        YMGroupInfo *groupInfo = [conversation valueForKey:@"groupInfo"];
        [self.headImageView sd_setImageWithURL:[NSURL URLWithString:groupInfo.groupAvatar]];
        self.nameLable.text = [NSString stringWithFormat:@"%@",groupInfo.groupName];
        self.roomLable.text = [NSString stringWithFormat:@"聊天室ID：%@",groupInfo.groupId];
    
        NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:1];
        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        self.dataArray = [conversation valueForKey:@"userList"];
        self.numLable.text = [NSString stringWithFormat:@"共%ld人",self.dataArray.count];
      
        
        self.isTop = groupInfo.isTop;
        self.isDisturb = groupInfo.isDisturb;
        [self.tableView reloadData];
        

        YMGroupUserInfo *groupUserInfo = [conversation valueForKey:@"userList"][0];
        NSDictionary *dic = (NSDictionary *)[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"];
        YMUserInfo *userInfo = [YMUserInfo mj_objectWithKeyValues:dic];
        if ([userInfo.userId intValue] == [groupUserInfo.userId intValue]) {
            //聊天室管理员
            self.userType = 0;
            [self.deleteButton setTitle:@"解散聊天室" forState:UIControlStateNormal];
            [self.deleteButton removeTarget:self action:@selector(sigoutRoomAction) forControlEvents:UIControlEventTouchUpInside];
            [self.deleteButton addTarget:self action:@selector(deleteRoomAction) forControlEvents:UIControlEventTouchUpInside];
         
            
        }else{
            
            //聊天室成员
            self.userType = 1;
            [self.deleteButton setTitle:@"离开聊天室" forState:UIControlStateNormal];
            [self.deleteButton removeTarget:self action:@selector(deleteRoomAction) forControlEvents:UIControlEventTouchUpInside];
            [self.deleteButton addTarget:self action:@selector(sigoutRoomAction) forControlEvents:UIControlEventTouchUpInside];
           
        }
        [self.collectionView reloadData];
        float count = (self.dataArray.count+2) /6.00;
        self.collectionView.height = (ceilf(count))*85+30;
        self.headerView.height =  self.collectionView.height+130;
        [self.tableView beginUpdates];
        [self.tableView setTableHeaderView:self.headerView];
        [self.tableView endUpdates];
       
        
    }];
    
}
-(void)initview{
    
    [self.view addSubview:self.tableView];
    [self.headerView addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.headerView.mas_top).offset(15);
        make.left.mas_equalTo(self.headerView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(70, 70));
        
    }];
    
    [self.headerView addSubview:self.nameLable];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
        make.top.mas_equalTo(self.headImageView.mas_top).offset(10);
        
    }];

    [self.headerView addSubview:self.roomLable];
    [self.roomLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.nameLable.mas_left);
        make.bottom.mas_equalTo(self.headImageView.mas_bottom).offset(-10);
        
    }];
    
    [self.footerView addSubview:self.deleteButton];
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.footerView.mas_top).offset(50);
        make.centerX.mas_equalTo(self.footerView.mas_centerX);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width-100);
        make.height.mas_equalTo(45);
    }];
    
    
}
#pragma mark 创建collextinview
- (void)initCollectionView
{
    UIView *lineview = [[UIView alloc]init];
    lineview.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
    [self.headerView addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.top.mas_equalTo(self.headImageView.mas_bottom).offset(15);
            
    }];
    
    [self.headerView addSubview:self.inforLable];
    [self.headerView addSubview:self.numLable];
    [self.inforLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.headerView.mas_left).offset(15);
        make.top.mas_equalTo(lineview.mas_bottom).offset(10);
        
    }];
    [self.numLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.headerView.mas_right).offset(-25);
        make.centerY.mas_equalTo(self.inforLable.mas_centerY);
        
    }];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    //设置CollectionView的属性
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 145,SCREEN_WIDTH, 100) collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.allowsMultipleSelection = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    [self.collectionView registerClass:[GroupCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.headerView addSubview:self.collectionView];



}

#pragma mark  设置CollectionView的组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

#pragma mark  设置CollectionView每组所包含的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.userType == 0) {
        
        return self.dataArray.count+2;
        
    }else{
        
        return self.dataArray.count+1;
    }

}

#pragma mark  设置CollectionCell的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    static NSString *identify = @"cell";
    GroupCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    if (indexPath.row == self.dataArray.count) {

        cell.deleteButton.hidden = YES;
        cell.addButton.hidden = NO;
        cell.headImageView.hidden = YES;
        cell.nameLable.hidden = YES;
        [cell.addButton addTarget:self action:@selector(addMember) forControlEvents:UIControlEventTouchUpInside];

    }else if (indexPath.row == self.dataArray.count+1){
        
       [cell.deleteButton addTarget:self action:@selector(deleteMember) forControlEvents:UIControlEventTouchUpInside];
        cell.deleteButton.hidden = NO;
        cell.addButton.hidden = YES;
        cell.headImageView.hidden = YES;
        cell.nameLable.hidden = YES;
        
    }else{
      
        cell.userInfo = [self.dataArray objectAtIndex:indexPath.row];
        cell.deleteButton.hidden = YES;
        cell.addButton.hidden = YES;
        cell.headImageView.hidden = NO;
        cell.nameLable.hidden = NO;
    }
    return cell;
    
}

#pragma mark  定义每个UICollectionView的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  CGSizeMake(55,85);
}


#pragma mark  定义整个CollectionViewCell与整个View的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 15, 0, 15);//（上、左、下、右）
}

#pragma mark  定义每个UICollectionView的横向间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}


#pragma mark  定义每个UICollectionView的纵向间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.userType==0) {
        
        if (indexPath.row==0) {
            
        }else{
            
            YMUserInfo *userInfo = [self.dataArray objectAtIndex:indexPath.row];
            [self muteOrUnmuteWithUserId:userInfo.userId userName:userInfo.userName];
        }
    }
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section==1) {
        
        return 2;
    }else{
        
        return 1;
    }

 
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    if (indexPath.section==0) {
        
        if (indexPath.row==0) {
            
            cell.textLabel.text = @"修改聊天室名称";
            self.nickNameLable.text = self.nickName;
            [cell.contentView addSubview:self.nickNameLable];
            [self.nickNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.right.mas_equalTo(cell.contentView.mas_right).offset(-15);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
                make.width.mas_equalTo(160);
            }];
        
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        
    }else if (indexPath.section==1){
        
        
        if (indexPath.row==0) {
            
            cell.textLabel.text = @"消息免打扰";
            cell.textLabel.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:self.distubSwithBtn];
            self.distubSwithBtn.on = self.isDisturb;
            [self.distubSwithBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.right.mas_equalTo(cell.contentView.mas_right).offset(-15);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            }];
            
        }else if (indexPath.row==1){
            
            cell.textLabel.text = @"置顶聊天";
            cell.textLabel.font =[UIFont systemFontOfSize:15];;
            [cell.contentView addSubview:self.skiTopSwithBtn];
           
            self.skiTopSwithBtn.on = self.isTop;
            [self.skiTopSwithBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.right.mas_equalTo(cell.contentView.mas_right).offset(-15);
                make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            }];
            
        }
        cell.accessoryType = UITableViewCellAccessoryNone;
        
    }else if (indexPath.section==2){
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = @"清空聊天记录";
        cell.textLabel.font =[UIFont systemFontOfSize:15];;
        
    }
    
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
      return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {
        
        GroupNameViewController *vc = [[GroupNameViewController alloc]init];
        vc.groupId = self.roomId;
        [vc setModifyName:^(NSString * _Nonnull name) {
           
            [self loadData];
            
        }];
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.section==2){
        
        [self clearHistory];
    }
  
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   return 55;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}
#pragma mark 移除聊天室成员
-(void)deleteMember{
    
    ContactViewController *vc = [[ContactViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.showSelect = YES;
    vc.title = @"移除聊天室成员";
    vc.didSelectResultBlock = ^(NSArray * _Nonnull userArray) {
       
        [[YMIMClient sharedClient].roomManager kickRoomWithRoomId:self.roomId uids:userArray completion:^(YMErrorCode code) {
            
            [self.navigationController popViewControllerAnimated:YES];
            [self loadData];
        }];
      
    };
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark 添加聊天室成员
-(void)addMember{
    
    ContactViewController *vc = [[ContactViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.showSelect = YES;
    vc.title = @"添加聊天室成员";
    vc.didSelectResultBlock = ^(NSArray * _Nonnull userArray) {
       
        
        [[YMIMClient sharedClient].roomManager inviteIntoRoomWithRoomId:self.roomId uids:userArray completion:^(YMErrorCode code) {
            [self.navigationController popViewControllerAnimated:YES];
            [self loadData];
        }];
    
    };

    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 用户禁言和解除禁言
-(void)muteOrUnmuteWithUserId:(NSString *)uid userName:(NSString *)userName{

    if (self.muteType == 0) {
    
        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *muteAction = [UIAlertAction actionWithTitle:@"用户禁言" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            [[YMIMClient sharedClient].roomManager muteRoomWithRoomId:self.roomId uid:uid completion:^(YMErrorCode code) {
                
                NSString *message = [NSString stringWithFormat:@"已将用户%@禁言",userName];
                [self showHint:message];
                self.muteType = 1;
                
            }];

        }];
        UIAlertAction *kickAction = [UIAlertAction actionWithTitle:@"请离聊天室" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            [[YMIMClient sharedClient].roomManager kickRoomWithRoomId:self.roomId uids:(NSArray *)uid completion:^(YMErrorCode code) {
               
                NSString *message = [NSString stringWithFormat:@"已将%@请离聊天室",userName];
                [self showHint:message];
            }];

        }];

        UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

            

        }];

        [actionSheet addAction:muteAction];
        [actionSheet addAction:kickAction];
        [actionSheet addAction:cancleAction];
        [self presentViewController:actionSheet animated:YES completion:nil];
        
    }else if (self.muteType==1){
        
        UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *muteAction = [UIAlertAction actionWithTitle:@"用户解除禁言" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            [[YMIMClient sharedClient].roomManager unmuteRoomWithRoomId:self.roomId uid:uid completion:^(YMErrorCode code) {
                
                NSString *message = [NSString stringWithFormat:@"已将用户%@解除禁言",userName];
                [self showHint:message];
                self.muteType = 0;
                
            }];

        }];
      
        UIAlertAction *kickAction = [UIAlertAction actionWithTitle:@"请离聊天室" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            [[YMIMClient sharedClient].roomManager kickRoomWithRoomId:self.roomId uids:(NSArray *)uid completion:^(YMErrorCode code) {
               
                NSString *message = [NSString stringWithFormat:@"已将%@请离聊天室",userName];
                [self showHint:message];
            }];

        }];
        UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {


        }];

        [actionSheet addAction:muteAction];
        [actionSheet addAction:kickAction];
        [actionSheet addAction:cancleAction];
        [self presentViewController:actionSheet animated:YES completion:nil];
        
    }
    
}
#pragma mark 解散聊天室
-(void)deleteRoomAction{
    
    NSString *message = [NSString stringWithFormat:@"解散聊天室%@ ？",self.nameLable.text];
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确定要解散聊天室" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      
        [[YMIMClient sharedClient].roomManager dismissRoomWithRoomId:self.roomId completion:^(YMErrorCode code) {
            
            [self showHint:@"聊天室解散成功"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }];
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:confirm];
    [self presentViewController:alertVC animated:YES completion:nil];
    
}
#pragma mark 离开聊天室
-(void)sigoutRoomAction{
    
    NSString *message = [NSString stringWithFormat:@"离开聊天室%@ ？",self.nameLable.text];
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确定要离开聊天室" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      
        [[YMIMClient sharedClient].roomManager leaveRoomWithRoomId:self.roomId completion:^(YMErrorCode code) {
            
            [self showHint:@"成功离开聊天室"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }];
        
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:confirm];
    [self presentViewController:alertVC animated:YES completion:nil];
    
}
//消息免打扰
-(void)disturbAction{
    
    [[YMIMClient sharedClient].chatManager doNotDisturbConversationWithTargetId:self.roomId completion:^(YMErrorCode code) {
       
        [self showHint:@"设置成功"];
     
    }];
    
}
//置顶会话
-(void)skipOnAction{
    
    [[YMIMClient sharedClient].chatManager topConversationWithTargetId:self.roomId completion:^(YMErrorCode code) {
       
        [self showHint:@"设置成功"];

    }];
    
}
//清空聊天记录
-(void)clearHistory{
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"清空聊天记录" message:@"确定要清空聊天记录 ？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      
        [[YMIMClient sharedClient].chatManager clearMessageWithTargetId:self.roomId completion:^(YMErrorCode code) {
           
            [self showHint:@"清空聊天记录成功"];
            [self.navigationController popToRootViewControllerAnimated:YES];
            
        }];
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:confirm];
    [self presentViewController:alertVC animated:YES completion:nil];
   
}
-(UILabel *)numLable{
    
    if (_numLable == nil) {
        
        _numLable = [[UILabel alloc]init];
        _numLable.font = [UIFont systemFontOfSize:16];
        _numLable.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
    }
    
    return _numLable;
}
-(UILabel *)inforLable{
    
    if (_inforLable == nil) {
        
        _inforLable = [[UILabel alloc]init];
        _inforLable.text = @"聊天室成员";
        _inforLable.font = [UIFont boldSystemFontOfSize:18];
        _inforLable.textColor = [UIColor blackColor];
    }
    
    return _inforLable;
}
- (UIButton *)deleteButton {
    if (!_deleteButton) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_deleteButton setTitle:@"删除好友" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _deleteButton.titleLabel.font = [UIFont systemFontOfSize:16];
        _deleteButton.layer.cornerRadius = 20;
        _deleteButton.layer.masksToBounds = YES;
        _deleteButton.backgroundColor = [UIColor redColor];
//        [_deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
    }
    
    return _deleteButton;
}
-(UIView *)footerView{
    if (_footerView == nil) {
        
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3)];
        _footerView.backgroundColor = [UIColor whiteColor];
        
    }
    
    return _footerView;
}
-(UILabel *)nameLable{
    
    if (_nameLable == nil) {
        
        _nameLable = [[UILabel alloc]init];
        _nameLable.font = [UIFont systemFontOfSize:15];
        _nameLable.textColor = [UIColor blackColor];
    }
    
    return _nameLable;
}
-(UILabel *)roomLable{
    
    if (_roomLable == nil) {
        
        _roomLable = [[UILabel alloc]init];
        _roomLable.font = [UIFont systemFontOfSize:15];
        _roomLable.textColor = [UIColor blackColor];
    }
    
    return _roomLable;
}

-(UIView *)headerView{
    if (_headerView == nil) {
        
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 555)];
        _headerView.backgroundColor = [UIColor whiteColor];
        
    }
    
    return _headerView;
}
-(UIImageView *)headImageView{
    
    if (_headImageView == nil) {
        
        _headImageView = [[UIImageView alloc]init];
        _headImageView.layer.cornerRadius = 35;
        _headImageView.clipsToBounds = YES;
    }
    
    return _headImageView;
}
-(UILabel *)nickNameLable{
    
    if (_nickNameLable == nil) {
        
        _nickNameLable = [[UILabel alloc]init];
//        _nickNameLable.text = @"前去添加备注";
        _nickNameLable.font = [UIFont systemFontOfSize:15];
        _nickNameLable.textColor = [UIColor blackColor];
        _nickNameLable.textAlignment = NSTextAlignmentRight;
    }
    
    return _nickNameLable;
}
-(UISwitch *)skiTopSwithBtn{

    if (_skiTopSwithBtn == nil) {

        _skiTopSwithBtn = [[UISwitch alloc]init];
        _skiTopSwithBtn.transform = CGAffineTransformMakeScale(0.75, 0.75);
        _skiTopSwithBtn.onTintColor = [UIColor colorWithRed:88/255.0 green:142/255.0 blue:247/255.0 alpha:1];
        [_skiTopSwithBtn addTarget:self action:@selector(skipOnAction) forControlEvents:UIControlEventTouchUpInside];

    }

    return _skiTopSwithBtn;
}
-(UISwitch *)distubSwithBtn{

    if (_distubSwithBtn == nil) {

        _distubSwithBtn = [[UISwitch alloc]init];
        _distubSwithBtn.transform = CGAffineTransformMakeScale(0.75, 0.75);
        _distubSwithBtn.onTintColor = [UIColor colorWithRed:88/255.0 green:142/255.0 blue:247/255.0 alpha:1];
        [_distubSwithBtn addTarget:self action:@selector(disturbAction) forControlEvents:UIControlEventTouchUpInside];

    }

    return _distubSwithBtn;
}
- (UITableView *)tableView {
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableFooterView = self.footerView;
        _tableView.tableHeaderView = self.headerView;
        _tableView.estimatedRowHeight           = 44;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.bounces = NO;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
        }
       
    }
    return _tableView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
